Skip to content

Align description about props default between composition/options API #1707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 10, 2022

Conversation

tanquar
Copy link
Contributor

@tanquar tanquar commented May 9, 2022

Description of Problem

I spotted differences in the descriptions about the argument for prop default between composition/options API.

Composition API says:

  // Object with a default value
  propE: {
    type: Object,
    // Object or array defaults must be returned from
    // a factory function
    default() {
      return { message: 'hello' }
    }
  },

Options API says:

    // Object with a default value
    propE: {
      type: Object,
      // Object or array defaults must be returned from
      // a factory function. The function receives the raw
      // props received by the component as the argument.
      default(rawProps) {
        // default function receives the raw props object as argument
        return { message: 'hello' }
      }
    },

The difference seems to be introduced after
b0f5fff
and
046ea54
These are adding explanations about rowProps into the options API.

Proposed Solution

Apply the same explanations to composition API too.
The part

        // default function receives the raw props object as argument

looks duplicate of the main text, so I suggest to remove it as well.

Additional Information

I tested with following code and confirmed that both composition/options API provides the rawProps arg.

App.vue

<template>
  <div>
    <Comp :propA="43" />
    <Comp :propA="44" :propE="{ message: 'good day' }" />
    <Opt :propA="43" />
    <Opt :propA="44" :propE="{ message: 'good day' }" />
  </div>
</template>

Comp.vue

<template>
  <div>Comp: {{ propE }}</div>
</template>

<script setup>
defineProps({
  propA: {
    type: Number,
    default: 42,
  },
  propE: {
    type: Object,
    default(rawProps) {
      return {
        message: `hello ${rawProps.propA}`
      };
    },
  },
});
</script>

Opt.vue

<template>
  <div>Opt: {{ propE }}</div>
</template>

<script>
export default {
  props: {
    propA: {
      type: Number,
      default: 42,
    },
    propE: {
      type: Object,
      default(rawProps) {
        return {
          message: `hello ${rawProps.propA}`
        };
      },
    },
  }
};
</script>

@netlify
Copy link

netlify bot commented May 9, 2022

Deploy Preview for vuejs ready!

Name Link
🔨 Latest commit 9e34087
🔍 Latest deploy log https://app.netlify.com/sites/vuejs/deploys/6279800cafaa090008b9cc39
😎 Deploy Preview https://deploy-preview-1707--vuejs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

Copy link
Contributor

@skirtles-code skirtles-code left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good to me.

@skirtles-code skirtles-code merged commit 929f0d5 into vuejs:main May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants